﻿using HighlightPlus;
using QFramework;
using UnityEngine;

namespace Gp.Scripts.Core
{
    public class NormalOutlineState : UnitOutlineState
    {
        protected override void OnApply()
        {
            var com = Model.gameObject.GetOrAddComponent<HighlightEffect>();
            var highlightProfile = Helpers.ResHelper.LoadHighlightProfile("Normal");
            com.ProfileLoad(highlightProfile);
        }

        public override void TriggerHighlight()
        {
            if (!Model.TryGetComponent(out HighlightEffect com)) return;
            
            var color = Model.UnitReference.PlayerNumber == PlayerConst.PlayerUnitNumber 
                ? Color.green : Color.yellow;
            com.outlineColor = color;
            com.SetHighlighted(true);
        }

        public override void DisableHighlight()
        {
            if (!Model.TryGetComponent(out HighlightEffect com)) return;
            
            com.outlineColor = Color.white;
            com.SetHighlighted(false);
        }
    }
}